// * 外包人员管理table字段
import { admissionRequireStatus, exitStatus }  from './status'
import { approverStatus } from '@/views/interviewManagement/js/status'

function setFlexWidth(e){
  console.log(e, '喜喜')
  return 'auto'
}

// * 入场申请table字段
export const admissionTableColumn = [
  {
    name: "需求编号",
    value: "needsCode",
    width: '190px',
    render: (h, { row, listeners }) => {
      return h('div', {}, [
        h('span', {
          class: `
          ${ row.closeState  === 1? 'needsFinished': '' }
          ${ row.suspendState  === 1? 'pause': '' }
          ${ row.suspendState === 2? 'restore': '' }
          ${ row.closeState === 2? 'close': '' }
          `,
        }, [
          h('span', {}, row.needsCode),
          row.reuse === 1? h('span', { class: 'multiplex' }, ''): '',
        ])
      ])
    }
  },
  {
    name: "岗位名称",
    value: "positionName",
    width: '120px'
  },
  {
    name: "姓名",
    value: "userName",
  },
  {
    name: "一级部门",
    value: "dept_1",
    width: '120px'
  },
  {
    name: "二级部门",
    value: "dept_2",
    width: '120px',
  },
  {
    name: "三级部门",
    value: "dept_3",
  },
  {
    name: "四级部门",
    value: "dept_4",
  },
  {
    name: "五级部门",
    value: "dept_5",
  },
  // {
  //   name: "外包人员汇报对象",
  //   value: "higherupName",
  // },
  {
    name: "入场时间",
    value: "beginTime",
    width: '100px',
  },
  {
    name: "入场状态",
    render: (h, { row }) => {
      return h('span', {
        class: `${ admissionRequireStatus[row.status] && admissionRequireStatus[row.status].className}`
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, `${ (admissionRequireStatus[row.status] && admissionRequireStatus[row.status].label) || '--' }  `)
      ])
    }
  },
  {
    name: "审批状态",
    render: (h, { row, listeners }) => {
      return h('span', {
        class: `${approverStatus[row.approvalState - 0].className}`,
        on: {
          click: function () {
            listeners.click('onApproveDetail')
          }
        }
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, `${approverStatus[row.approvalState - 0].label}`)
      ])
    }
  },
  {
    name: "操作",
    type: "operate",
    width: '180px',
    fixed: "right",
    render: (h, { row, listeners }) => {
      return h('div', {
        class: 'table-btn-group'
      }, [
        row.status == '0' || ['3', '4', '5'].includes(row.approvalState) ? h('span', {
          class: `cursor table-btn color-pink ${ [1, 2].includes(row.closeState) ? 'disabled' : '' }`,
          on: {
            click: function () {
              listeners.click('onToEntrance')
            }
          }
        }, '入场申请') : null,
        row.status == '1' && row.approvalState == '2' ? h('span', {
          class: `cursor table-btn table-blue-btn ${ [1, 2].includes(row.closeState) ? 'disabled' : '' }`,
          on: {
            click: function () {
              listeners.click('onEnterEntrance')
            }
          }
        }, '确认入场') : null,
        row.status == '1'  && row.approvalState == '2' ? h('span', {
          class: `cursor table-btn color-pink ${ [1, 2].includes(row.closeState) ? 'disabled' : '' }`,
          on: {
            click: function () {
              listeners.click('onQuitEntrance')
            }
          }
        }, '终止入场') : null,
        row.status != '0' ? h('span', {
          class: `cursor table-btn table-blue-btn`,
          on: {
            click: function () {
              listeners.click('onLookDetail')
            }
          }
        }, '查看') : null,
        row.remind === 1? h(
          "span",
          {
            class: "cursor table-btn table-blue-btn",
            on: {
              click: function () {
                listeners.click("onRemind");
              },
            },
          },
          "入场审批提醒"
        ): '',
      ], null)
    }
  },
]

// * 人员信息table字段
export const personnelInfoTableColumn = [
  {
    name: "员工编号",
    value: "workCode",
  },
  {
    name: "姓名",
    value: "userName",
  },
  {
    name: "岗位",
    value: "positionName",
  },
  {
    name: "一级部门",
    value: "dept_1",
  },
  {
    name: "二级部门",
    value: "dept_2",
  },
  {
    name: "三级部门",
    value: "dept_3",
  },
  {
    name: "四级部门",
    value: "dept_4",
  },
  {
    name: "五级部门",
    value: "dept_5",
  },
  {
    name: "入场时间",
    value: "admitTime",
  },
  {
    name: "审批状态",
    render: (h, { row, listeners }) => {
      return h('span', {
        class: `${row.approvalState && approverStatus[row.approvalState - 0].className }`,
        on: {
          click: function () {
            listeners.click('onApproveDetail')
          }
        }
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, `${ (row.approvalState && approverStatus[row.approvalState - 0].label) || '--' }`)
      ])
    }
  },
  {
    name: "操作",
    type: "operate",
    width: '120px',
    fixed: "right",
    render: (h, { row, listeners }) => {
      return h('div', {
        class: 'table-btn-group'
      }, [
        !row.outId || [3,4,5].includes(row.approvalState)? h('span', {
          class: `cursor table-btn look-btn color-pink ${ [1, 2].includes(row.closeState) ? 'disabled' : '' }`,
          on: {
            click: function () {
              listeners.click('onToEntrance')
            }
          }
        }, '申请离场') : null,
         h('span', {
          class: `cursor table-btn table-blue-btn`,
          on: {
            click: function () {
              listeners.click('onLookDetail')
            }
          }
        }, '查看')
      ], null)
    }
  },
]

// * 离场管理table字段
export const exitTableColumn = [
  {
    name: "员工编号",
    value: "workCode",
  },
  {
    name: "姓名",
    value: "userName",
  },
  {
    name: "岗位名称",
    value: "positionName",
    width: '120px',
  },
  {
    name: "一级部门",
    value: "dept_1",
    width: '120px',
  },
  {
    name: "二级部门",
    value: "dept_2",
    width: '120px',
  },
  {
    name: "三级部门",
    value: "dept_3",
    width: '120px',
  },
  {
    name: "四级部门",
    value: "dept_4",
    width: '120px',
  },
  {
    name: "五级部门",
    value: "dept_5",
  },
  {
    name: "入场时间",
    width: '100px',
    render: (h, { row }) => {
      const { admitTime } = row
      return h('span', {}, !admitTime ? '--' : admitTime.split(' ')[0])
    }
  },
  {
    name: "离场时间",
    width: '100px',
    render: (h, { row }) => {
      const { outDate } = row
      return h('span', {}, !outDate ? '--' : outDate.split(' ')[0])
    }
  },
  {
    name: "离场状态",
    render: (h, { row }) => {
      return h('span', {
        class: exitStatus[row.outState].className
      }, exitStatus[row.outState].label)
    }
  },
  {
    name: "审批状态",
    render: (h, { row, listeners }) => {
      return h('span', {
        class: `${approverStatus[row.approvalState].className}`,
        on: {
          click: function () {
            listeners.click('onApproveDetail')
          }
        }
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, `${approverStatus[row.approvalState].label}`),
      ])
    }
  },
  {
    name: "操作",
    type: "operate",
    width: '150px',
    fixed: "right",
    render: (h, { row, listeners }) => {
      // * 离场时间小于等于当前时间条件下，激活确认离场按钮
      const nowTime = new Date().getTime()
      const outTime = row.outDate ? new Date(row.outDate).getTime() : null
      const isOpenOutBtn = outTime && outTime <= nowTime ? true : false
      return [
        row.outState == '1' && row.approvalState == '2' && isOpenOutBtn ? h('span', {
          class: `cursor table-btn table-blue-btn color-pink  ${ [1, 2].includes(row.closeState) ? 'disabled' : '' }`,
          on: {
            click: function () {
              listeners.click('enterLeave')
            }
          }
        }, '确认离场') : null,
        row.outState == '1' && row.approvalState == '3' ? h('span', {
          class: `cursor table-btn table-blue-btn color-pink  ${ [1, 2].includes(row.closeState) ? 'disabled' : '' }`,
          on: {
            click: function () {
              listeners.click('onToEntrance')
            }
          }
        }, '申请离场') : null,
        h('span', {
          class: `cursor table-btn table-blue-btn`,
          on: {
            click: function () {
              listeners.click('onLookDetail')
            }
          }
        }, '查看'),
        row.remind === 1? h(
          "span",
          {
            class: "cursor table-btn table-blue-btn",
            on: {
              click: function () {
                listeners.click("onRemind");
              },
            },
          },
          "离场审批提醒"
        ): '',
      ]
    }
  },
]
